/**
 * 检查字符串结尾
 * @param str
 * @param target
 * @returns {boolean}
 * String.substr()
 */

function confirmEnding(str, target) {
    // console.log(str.length);
    let start = str.length-target.length;
    let arr = str.substr(start,target.length);

    if(arr === target){
         return true;
    }
    return false;
}

//confirmEnding("Bastian", "xan");
console.log(confirmEnding("He has to give me a new name", "name"));